#!/bin/sh

CRON_FEATURE_DIR="/var/spool/cron/crontabs"

case "$1" in
	start)
		printf "Starting cron ... "
        if [ ! -d "$CRON_FEATURE_DIR" ];then
            mkdir -p $CRON_FEATURE_DIR
        fi
        cp /etc/cron.d/crontabs $CRON_FEATURE_DIR/root

		start-stop-daemon -S -q -m -b -p /var/run/dcron.pid --exec /usr/sbin/crond -- -f -L /dev/null
		echo "done."
		;;
	stop)
		printf "Stopping cron ..."
		start-stop-daemon -K -q -p /var/run/dcron.pid
		echo "done."
		;;
	restart)
		$0 stop
		sleep 1
		$0 start
		;;
	*)
		echo "usage: $0 {start|stop|restart}"
		;;
esac
